/*
 * $Id: ActRequestPropertiesDAO.java,v 1.4 2009/07/10 14:50:16 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.ActRequestProperties;

/**
 * @author 212042764
 * 
 */
public class ActRequestPropertiesDAO extends BaseDAO implements
		IRequestPropertiesDAO {
	/**
	 * Eclispe generated
	 */
	private static final long serialVersionUID = -3921365932056690217L;

	public ActRequestPropertiesDAO() {
		super(ActRequestProperties.TABLE_NAME);
	}

	public void save(Object pojo) {
		super.save(pojo);
	}

	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	public void refresh(Object pojo) {
		super.refresh(pojo);
	}

	/**
	 * @param requestId
	 * @return
	 */
	public Map<String, String> getRequestPropertiesByRequestId(Long requestId) {
		List<?> rtvdProperties = this.findByProperty(ActRequestProperties.COL_REQUEST_ID, requestId);
		if (ASCUtil.isNullOrEmptyList(rtvdProperties)) {
			return null;
		}
		Map<String, String> requestPropertiesMap = new HashMap<String, String>();
		for (int iCount = 0; iCount < rtvdProperties.size(); iCount++) {
			ActRequestProperties requestProperty = (ActRequestProperties) rtvdProperties
					.get(iCount);
			requestPropertiesMap.put(requestProperty.getPropertyName(),
					requestProperty.getPropertyValue());
		}
		return requestPropertiesMap;
	}
	
	/**
	 * @param requestId
	 * @return
	 */
	public ActRequestProperties getRequestPropertiesByRequestIdAndName(Long requestId, String name) {
		Map<String, Object> whereClause = new HashMap<String, Object>();
		whereClause.put(ActRequestProperties.COL_REQUEST_ID, requestId);
		whereClause.put(ActRequestProperties.COL_PROPERTY_NAME, name);
		List<?> rtvdProperties = this.findByProperties(whereClause);
		if (ASCUtil.isNullOrEmptyList(rtvdProperties)) {
			return null;
		}
		return (ActRequestProperties)rtvdProperties.get(0);
	}
	
	public ActRequestProperties addRequestProperties(Long requestId, String name, String value) {
		ActRequestProperties requestProperty = new ActRequestProperties();
		requestProperty.setRequestId(requestId);
		requestProperty.setPropertyName(name);
		requestProperty.setPropertyValue(value);
		this.save(requestProperty);
		return requestProperty;
	}
}
